import { TimePicker } from 'antd'
import moment from 'moment'
/*
时间范围选择 TimePicker.RangePicker
           value            当前时间
           onChange         时间发生变化的回调
           disabledTime     不可选择的时间
           startTimeName    name
           endTimeName      name
           defaultOpenValue  初始可见的面板

const [timeRange, setTimeRange] = useState([null, null])
const onChange = (times, timeStrings) => {
  console.log('Selected times:', times)
  console.log('Selected time strings:', timeStrings)
  setTimeRange(times)
}
const disabledTime = current => {
  return current && current.valueOf() < Date.now()
}

<TimeRangePicker value={timeRange} onChange={onChange} disabledTime={disabledTime} />

*/
const TimeRangePicker = ({
  value,
  onChange,
  startTimeName = '开始时间',
  endTimeName = '结束时间',
  defaultOpenValue = [moment('00:00:00', 'HH:mm:ss'), moment('00:00:00', 'HH:mm:ss')],
  disabledTime,
  ...rest
}) => {
  return (
    <TimePicker.RangePicker
      value={value}
      onChange={onChange}
      disabledTime={disabledTime}
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-expect-error
      defaultOpenValue={defaultOpenValue}
      placeholder={[startTimeName, endTimeName]}
      {...rest}
    />
  )
}

export default TimeRangePicker
